package com.teach.controller.photo;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.teach.dto.LoginUser;
import com.teach.entity.PhotoGreat;
import com.teach.entity.PhotoPic;
import com.teach.service.photo.PhotoGreatService;

@RestController
@RequestMapping("/photo")
public class PhotoGreatController {

	@Autowired
	private PhotoGreatService greatService;
	
	
	@RequestMapping("picGreat.do")
	public Object doGeart(LoginUser user,
			@RequestParam("picId")Long picId,
			@RequestParam("title")String title,
			@RequestParam("writerId")String writerId,
			@RequestParam("picClassId")Long picClassId) {
		PhotoGreat great = new PhotoGreat();
		great.setPhotoGreatUserId(user.getUserName());
		great.setPhotoPicId(picId);
		great.setPhotoGreatTime(new Date());
		great.setPhotoStatus("点赞");
		PhotoPic pic = new PhotoPic();
		pic.setPhotoPicTitle(title);
		pic.setPhotoWriterId(writerId);
		pic.setPhotoPicClassId(picClassId);
		return greatService.insertUpdateGreat(great, pic);		
	}
	
	@RequestMapping("picRemoveGreat.do")
	public Object doRomoveGeart(LoginUser user,
			@RequestParam("picId")Long picId,
			@RequestParam("title")String title,
			@RequestParam("writerId")String writerId,
			@RequestParam("picClassId")Long picClassId) {
		PhotoPic pic = new PhotoPic();
		pic.setPhotoPicTitle(title);
		pic.setPhotoWriterId(writerId);
		pic.setPhotoPicClassId(picClassId);
		return greatService.updateStatus("取消点赞", picId, user.getUserName(), pic);
		
	}
}
